function formatStrToJSON(str) {
  // console.log('start');
  const reg = /\((.*?)\)/i;

  // console.log(str.match(reg)[1]);

  return JSON.parse(str.match(reg)[1]);

}

//将请求的后端数据存入localStorage
function setLocalList(data) {
  localStorage.setItem('phoneData', JSON.stringify(data));
}

/**
 * 将修改好的state数据同步到localStorage
 * @param {*} data 修改好的state数据对象
 */
function setStorage(data) {
  const {
    totalMount,
    totalPrice,
    cartData
  } = data;

  localStorage.setItem("totalMount", totalMount);
  localStorage.setItem("totalPrice", totalPrice);
  localStorage.setItem("cartData", JSON.stringify(cartData));
}

export {
  formatStrToJSON,
  setLocalList,
  setStorage
}